import 'package:color_dart/RgbaColor.dart';
import "package:flutter/material.dart";
import 'package:im_flutter_sdk_example/jsonserialize/recommend/news.dart';
import 'package:im_flutter_sdk_example/utils/global.dart';
import 'package:im_flutter_sdk_example/utils/time_util.dart';
import 'package:im_flutter_sdk_example/utils/screen.dart';

/*
 *@功能: 单图 新闻
 *@author: lovecrosszhu
 *@date: 2021-02-09 11:49:49
 *@version: V1.0.0
*/

Widget _buildImage(String path) {
  return Image.network(
    G.thumbImage112_80(path),
    width: 224.w,
    height: 160.h,
    fit: BoxFit.cover,
  );
}

class NewsItem extends StatelessWidget {
  final NewsData item;
  const NewsItem({Key key, this.item}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => {G.pushNamed('/news_detail', arguments: item)},
      child: Container(
        width: double.infinity,
        padding: EdgeInsets.symmetric(vertical: 0.h, horizontal: 32.w),
        margin: EdgeInsets.only(top: 38.h),
        // color: Colors.red,
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(
                  child: Container(
                    height: 160.h,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text('${item.title}',
                            maxLines: 2,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(
                                color: rgba(51, 51, 51, 1),
                                fontSize: 16,
                                fontWeight: FontWeight.w500)),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Text(
                              '${item.agentsource == null ? '' : item.agentsource + '·'}${TimeUtil.getFormatTime(item.date)}',
                              style: TextStyle(
                                  color: rgba(191, 191, 191, 1), fontSize: 12),
                            ),
                            item.comments == 0
                                ? Text('')
                                : Text(
                                    '${item.comments} 评论',
                                    style: TextStyle(
                                        color: rgba(191, 191, 191, 1),
                                        fontSize: 12),
                                  )
                          ],
                        ),
                      ],
                    ),
                  ),
                ),
                Container(
                  width: 224.w,
                  height: 160.h,
                  margin: EdgeInsets.only(left: 12),
                  child: _buildImage('${item.fileUrls[0]}'),
                  // child: Image.network(
                  //   '${item.fileUrls[0]}',
                  //   fit: BoxFit.cover,
                  // ),
                ),
              ],
            ),
            Container(
              margin: EdgeInsets.only(top: 24.h),
              child: Divider(
                  color: rgba(242, 242, 242, 1), thickness: 1.h, height: 1.h),
            ),
          ],
        ),
      ),
    );
  }
}

class NewsTextItem extends StatelessWidget {
  final NewsData item;
  const NewsTextItem({Key key, this.item}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => {G.pushNamed('/news_detail', arguments: item)},
      child: Container(
        padding: EdgeInsets.symmetric(vertical: 18.h),
        decoration:
            BoxDecoration(border: G.borderBottom(), color: Colors.white),
        child: ListTile(
            title: Text('${item.title}',
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                    color: rgba(51, 51, 51, 1),
                    fontSize: 16,
                    fontWeight: FontWeight.w500)),
            subtitle: Container(
              margin: EdgeInsets.only(top: 30.h),
              child: Column(
                children: [
                  Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                            '${item.agentsource == null ? '' : item.agentsource + '·'}${TimeUtil.getFormatTime(item.date)}',
                            style: TextStyle(
                                color: rgba(191, 191, 191, 1),
                                fontSize: 24.nsp)),
                        item.comments == 0
                            ? Text('')
                            : Text('${item.comments}评论',
                                style: TextStyle(
                                    color: rgba(191, 191, 191, 1),
                                    fontSize: 24.nsp))
                      ]),
                ],
              ),
            )),
      ),
    );
  }
}

class NewsItemMultiPic extends StatelessWidget {
  final NewsData item;
  const NewsItemMultiPic({Key key, this.item}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => {G.pushNamed('/news_detail', arguments: item)},
      child: Container(
        width: double.infinity,
        padding: EdgeInsets.symmetric(vertical: 16.h, horizontal: 32.w),
        color: Colors.white,
        // height: 384.h,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              margin: EdgeInsets.only(bottom: 18.h),
              child: Text(
                '${item.title}',
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                    color: rgba(51, 51, 51, 1),
                    fontSize: 16,
                    fontWeight: FontWeight.w500),
              ),
            ),
            Padding(
              padding: EdgeInsets.fromLTRB(0, 0.h, 0, 0.h),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  _buildImage('${item.fileUrls[0]}'),
                  _buildImage('${item.fileUrls[1]}'),
                  _buildImage('${item.fileUrls[2]}'),
                  // SizedBox(
                  //   child: Image.network(
                  //     '${item.fileUrls[]}',
                  //     width: 224.w,
                  //     height: 160.h,
                  //     fit: BoxFit.cover,
                  //   ),
                  // ),
                  // Image.network(
                  //   '${item.fileUrls[1]}',
                  //   width: 224.w,
                  //   height: 160.h,
                  //   fit: BoxFit.cover,
                  // ),
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 14.h),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(
                    '${item.agentsource == null ? '' : item.agentsource + " · "}${TimeUtil.getFormatTime(item.date)}',
                    style:
                        TextStyle(color: rgba(191, 191, 191, 1), fontSize: 12),
                  ),
                  (item.comments == 0 || item.comments == null)
                      ? Text('')
                      : Text(
                          '${item.comments}评论',
                          style: TextStyle(
                              color: rgba(191, 191, 191, 1), fontSize: 12),
                        ),
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 32.h),
              child: Divider(
                color: rgba(242, 242, 242, 1),
                height: 1.h,
                thickness: 1,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
